package com.ruoyi.web.controller.control;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.control.domain.Monorailcrane;
import com.ruoyi.control.service.IMonorailcraneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 单轨吊Controller
 *
 * @author ruoyi
 * @date 2024-12-20
 */
@RestController
@RequestMapping("/monorailcrane/monorailcrane")
public class MonorailcraneController extends BaseController
{
    @Autowired
    private IMonorailcraneService monorailcraneService;

    /**
     * 查询单轨吊列表
     */
    @PreAuthorize("@ss.hasPermi('monorailcrane:monorailcrane:list')")
    @GetMapping("/list")
    public TableDataInfo list(Monorailcrane monorailcrane)
    {
        startPage();
        List<Monorailcrane> list = monorailcraneService.selectMonorailcraneList(monorailcrane);
        return getDataTable(list);
    }

    /**
     * 导出单轨吊列表
     */
    @PreAuthorize("@ss.hasPermi('monorailcrane:monorailcrane:export')")
    @Log(title = "单轨吊", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Monorailcrane monorailcrane)
    {
        List<Monorailcrane> list = monorailcraneService.selectMonorailcraneList(monorailcrane);
        ExcelUtil<Monorailcrane> util = new ExcelUtil<Monorailcrane>(Monorailcrane.class);
        util.exportExcel(response, list, "单轨吊数据");
    }

    /**
     * 获取单轨吊详细信息
     */
    @PreAuthorize("@ss.hasPermi('monorailcrane:monorailcrane:query')")
    @GetMapping(value = "/{tagName}")
    public AjaxResult getInfo(@PathVariable("tagName") String tagName)
    {
        return success(monorailcraneService.selectMonorailcraneByTagName(tagName));
    }

    /**
     * 新增单轨吊
     */
    @PreAuthorize("@ss.hasPermi('monorailcrane:monorailcrane:add')")
    @Log(title = "单轨吊", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Monorailcrane monorailcrane)
    {
        return toAjax(monorailcraneService.insertMonorailcrane(monorailcrane));
    }

    /**
     * 修改单轨吊
     */
    @PreAuthorize("@ss.hasPermi('monorailcrane:monorailcrane:edit')")
    @Log(title = "单轨吊", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Monorailcrane monorailcrane)
    {
        return toAjax(monorailcraneService.updateMonorailcrane(monorailcrane));
    }

    /**
     * 删除单轨吊
     */
    @PreAuthorize("@ss.hasPermi('monorailcrane:monorailcrane:remove')")
    @Log(title = "单轨吊", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tagNames}")
    public AjaxResult remove(@PathVariable String[] tagNames)
    {
        return toAjax(monorailcraneService.deleteMonorailcraneByTagNames(tagNames));
    }
}
